const app = getApp()
Page({
  data: {
    configState: false,
    configContent: '',
    dialogBodyStyle: {
      width: '70%',
      height: '250rpx'
    },
    img: ''
  },
  onLoad: function (options) {

  },
  onShow: function () {

  },
  onPullDownRefresh: function () {

  },
  chooseImg(e) {
    let _this = this
    wx.chooseImage({
      count: 1, // 最多可以选择的图片张数，默认9
      sizeType: ['original', 'compressed'], // original 原图，compressed 压缩图，默认二者都有
      sourceType: ['album', 'camera'], // album 从相册选图，camera 使用相机，默认二者都有
      success: function (res) {
        // 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
        let tempFilePaths = res.tempFilePaths;
        app.Http.upload({
          url: app.Api.Upload,
          params: tempFilePaths[0],
          loading: true
        }).then(data => {
          _this.setData({
            img: data.data
          })
        }).catch(err => {
          console.log(err)
        })
      },
    });

  },
  close() {
    this.setData({
      configState: false
    })
  },
  formSubmit: function (e) {
    let subObj = e.detail.value
    if (!subObj.mobile) {
      this.setData({
        configState: true,
        configContent: '请填写手机号'
      })
      return
    }
    if (!subObj.content) {
      this.setData({
        configState: true,
        configContent: '请输入你要反馈的内容'
      })
      return
    }

    app.Http.http({
      url: app.Api.FeedbackSave,
      method: 'POST',
      params: {
        mobile: subObj.mobile,
        content: subObj.content,
        image: this.data.img
      }
    }).then(data => {
      wx.showToast({
        title: '提交成功！',
        icon: 'success',
        duration: 100,
        mask: !0,
      })
      setTimeout(() => {
        wx.hideToast()
      }, 1000)

    }).catch(err => {
      console.log(err)
    })
  },
  changeData(data) {

  }
})